package com.ikm.demo.controller;

import com.ikm.demo.entity.SysOrgPerson;
import com.ikm.demo.service.SysOrgPersonService;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class BipoController {

    @Autowired
    private SysOrgPersonService sysOrgPersonService;

    @RequestMapping(value="/api/bipo",method = RequestMethod.POST)
    public String callBipo() throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
        RequestBody body = RequestBody.create(mediaType, "UserName=hrm&Password=password&grant_type=password&client_id=145BFE3F-D331-407D-85F4-F4D86216BB41&client_secret=02A41E1D-6331-4313-837A-AD38F326CA7D");
        Request request = new Request.Builder()
                .url("https://hrms7.bipocloud.com/novo/oauth2/webapi/token")
                .method("POST", body)
                .addHeader("Content-Type", "application/x-www-form-urlencoded")
                .build();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }
}
